package com.itheima.day06_demo;

/**
 * 请把一个整型数组，例如存了数据：11,22,33，拷贝成一个一模一样的新数组出来。
 */
public class Demo5_Copy_array {
    public static void main(String[] args) {
        int[] arr1 = {11,22,33};
        int[] arr2 = copy(arr1);
        printArray(arr2);
        arr2[1] = 666;
        System.out.println("arr1[1] = " + arr1[1]);
        System.out.println("arr2[1] = " + arr2[1]);
    }
    public static int[] copy(int[] arr){
        int[] newArr = new int[arr.length];
        for (int i = 0; i < arr.length; i++) {
            newArr[i] = arr[i];
        }
        return newArr;
    }
    public static void printArray(int[] arr){
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println();
    }
}
